﻿<Application
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:Corss_LehaKondr" x:Class="Corss_LehaKondr.App"
             StartupUri="MainWindow.xaml">
    <Application.Resources>

        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
        <SolidColorBrush x:Key="CorssCellBorder" Color="#FF7F7F7F"/>
        <SolidColorBrush x:Key="CorssCellUnusableBackground" Color="#FF000000"/>
        <SolidColorBrush x:Key="CorssCellInsertMask" Color="#70FF0000"/>
        <SolidColorBrush x:Key="CorssCellGoodInsertMask" Color="Lime"/>

        <Style TargetType="{x:Type local:Cell}">
            <Style.Resources>
                <Storyboard x:Key="Storyboard1"/>
            </Style.Resources>
            <Style.Triggers>
                <Trigger Property="isUsable" Value="False">
                    <Trigger.Setters>
                        <Setter Property="Background" Value="{DynamicResource CorssCellUnusableBackground}"/>
                    </Trigger.Setters>
                </Trigger>
            </Style.Triggers>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type local:Cell}">
                        <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" OpacityMask="{TemplateBinding OpacityMask}" Width="{TemplateBinding ActualHeight}" BorderThickness="{TemplateBinding BorderThickness}">
                            <Grid>
                                <Border x:Name="GoodMaskBorder" />
                                <Border x:Name="insertMaskBorder" />
                                <Grid Visibility="{Binding isUsable, Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource TemplatedParent}}">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="{Binding ActualHeight, ElementName=textBlock, Mode=OneWay}"/>
                                        <RowDefinition/>
                                    </Grid.RowDefinitions>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="{Binding ActualWidth, ElementName=textBlock, Mode=OneWay}"/>
                                        <ColumnDefinition/>
                                    </Grid.ColumnDefinitions>
                                    <TextBlock x:Name="textBlock" Text="{Binding AskNumber, RelativeSource={RelativeSource TemplatedParent}, StringFormat=\{0:D\}}" FontSize="{Binding FontSizeNumber, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" HorizontalAlignment="Left" VerticalAlignment="Top" Padding="1,1,0,0" FontFamily="{TemplateBinding FontFamily}"  Visibility="{TemplateBinding isAnswerStart, Converter={StaticResource BooleanToVisibilityConverter}}"/>
                                    <TextBlock Text="{TemplateBinding Text}" Grid.RowSpan="2" Grid.ColumnSpan="2" VerticalAlignment="Center" Margin="2,4,2,0" HorizontalAlignment="Center" FontSize="{TemplateBinding FontSize}" FontFamily="{TemplateBinding FontFamily}" />
                                </Grid>
                            </Grid>
                        </Border>
                        <ControlTemplate.Triggers>
                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition Property="ShowGoodInsertMask" Value="True"/>
                                    <Condition Property="isUsable" Value="True"/>
                                </MultiTrigger.Conditions>
                                <Setter Property="Background" TargetName="GoodMaskBorder" Value="{Binding GoodInsertMask, RelativeSource={RelativeSource TemplatedParent}}"/>
                            </MultiTrigger>
                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition Property="ShowInsertMask" Value="True"/>
                                    <!--<Condition Property="ShowGoodInsertMask" Value="False"/>-->
                                </MultiTrigger.Conditions>
                                <Setter Property="Background" TargetName="insertMaskBorder" Value="{Binding InsertMask, RelativeSource={RelativeSource TemplatedParent}}"/>
                            </MultiTrigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="Background" Value="White"/>
            <Setter Property="FontSize" Value="16"/>
            <Setter Property="MinHeight" Value="26"/>
            <Setter Property="MinWidth" Value="26"/>
            <Setter Property="BorderThickness" Value="1,1,0,0"/>
            <Setter Property="BorderBrush" Value="{DynamicResource CorssCellBorder}"/>
            <Setter Property="InsertMask" Value="{DynamicResource CorssCellInsertMask}"/>
            <Setter Property="GoodInsertMask" Value="{DynamicResource CorssCellGoodInsertMask}"/>
        </Style>
        <DataTemplate DataType="{x:Type local:Ask}" x:Key="AskDataTemplate">
        	<StackPanel Orientation="Horizontal">
        		<TextBlock ><Run Text="{Binding Number, Mode=OneWay, StringFormat=\{0:D\}}"/><Run Text=". "/><Run Text="{Binding Answer}"/><Run Text=" - "/><Run Text="{Binding TextAsk}"/></TextBlock>
        	</StackPanel>
        </DataTemplate>

    </Application.Resources>
</Application>
